﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using WpfPractice.MVVM;

namespace WpfPractice.ViewModel
{
    public class BindingTestViewModel : INotifyPropertyChanged
    {
        public BindingTestViewModel()
        {
            MyCommand = new DelegateCommand(Show);
            //MyCommand = new DelegateCommand(() => { MessageBox.Show("点击了command按钮"); });
        }
        // 定义了个只读属性
        //只读属性无法进行 TwoWay 或 OneWayToSource
        public string Name => "zzz";
        private string _info;

        public string Info
        {
            get { return _info; }
            set
            {
                _info = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Info"));
            }
        }
        public string Detail { get; set; }
        //这样写定义的是字段是不对的，Binding绑定的只能是属性而不是字段
        //public DelegateCommand MyCommands = new DelegateCommand(() => { MessageBox.Show("点击了按钮"); });
        public DelegateCommand MyCommand { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        public void Show()
        {
            Info = "修改了Info";
            MessageBox.Show($"点击了按钮，显示Info{Info}");
        }
    }
}
